package com.code.spring.mvc.action;

import com.code.spring.mvc.service.IDemoService;
import com.code.spring.mvcframework.annotation.SoulAutowired;
import com.code.spring.mvcframework.annotation.SoulController;
import com.code.spring.mvcframework.annotation.SoulRequestMapping;
import com.code.spring.mvcframework.annotation.SoulRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


//虽然，用法一样，但是没有功能
@SoulController
@SoulRequestMapping("/demo")
public class DemoAction {

  	@SoulAutowired
	private IDemoService demoService;

	@SoulRequestMapping("/query")
	public void query(HttpServletRequest req, HttpServletResponse resp,
					  @SoulRequestParam("name") String name){
//		String result = demoService.get(name);
		String result = "My name is " + name;
		try {
			resp.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@SoulRequestMapping("/add")
	public void add(HttpServletRequest req, HttpServletResponse resp,
					@SoulRequestParam("a") Integer a, @SoulRequestParam("b") Integer b){
		try {
			resp.getWriter().write(a + "+" + b + "=" + (a + b));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@SoulRequestMapping("/sub")
	public void add(HttpServletRequest req, HttpServletResponse resp,
					@SoulRequestParam("a") Double a, @SoulRequestParam("b") Double b){
		try {
			resp.getWriter().write(a + "-" + b + "=" + (a - b));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@SoulRequestMapping("/remove")
	public String  remove(@SoulRequestParam("id") Integer id){
		return "" + id;
	}

}
